<?php 

class OrderControl extends  CommonControl
{
    /**
     * 订单首页显示
     * @return [type] [description]
     */
    public function index()
    {
        isset($_SESSION['user'])?$_SESSION['user']:$_SESSION['user']=array();
        if($_SESSION['user']){
            $this->assign('SESSION',$_SESSION);
            $this->display('order');
        }else{
            $this->error('请先登陆',"Login/login",1);
        }
        
    }

    /**
     * 订单提交
     */
    public function add()
    {
        $_POST['order_time'] = date(time());
        $_POST['user_uid'] = $_SESSION['user']['uid'];
        $_POST['total_price'] = $_SESSION['cart']['total_price'];
        $_POST['order_number'] = $_SESSION['user']['uid'].mb_substr(date(time()),0,4).mt_rand(100,999);
        $db = M('g_order');
        $order_id = $db ->add();
        $order_list = array();
        foreach ($_SESSION['cart']['goods'] as $k ) 
        {
            $order_list['goods_order_order_id'] = $order_id;
            $order_list['goods_list_glid'] = $k['st_id'];
            $order_list['price'] = $k['price'];
            $order_list['num'] = $k['gcount'];
            $db->table("g_order_list")->add($order_list);
        }
        $_SESSION['cart'] = array();
        $this->success('提交订单成功',"Member/index");
    }
}























 ?>